package bos.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import bos.dao.IRoleDao;
import bos.domain.Function;
import bos.domain.Role;
import bos.service.IRoleService;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {
@Autowired
private IRoleDao roleDao;
@Resource
private IdentityService identityService;

	@Override
	public void save(Role role, String ids) {
		
		roleDao.save(role);
		
		
		Group group=new GroupEntity(role.getName());
		identityService.saveGroup(group);
		
		String[] functionIds=ids.split(",");
		for(String fid: functionIds){
			Function function=new Function(fid);
			role.getFunctions().add(function);
		}
	}

	@Override
	public List<Role> findAll() {
		return roleDao.findAll();
	}

}
